import {request} from '../../request/index.js'
const regeneratorRuntime = require('../../lib/runtime.js')
Page({
  data:{
    names:'',
  },
  async submitForm() {
      if (!(/\S/.test(this.data.names))) {
        wx.showToast({ title: '内容不为空', duration: 2000,icon:'none'}); 
        return false; 
      }
      else if (!(/^[\u4E00-\u9FA5A-Za-z].{3,17}$/.test(this.data.names))) { 
        wx.showToast({ title: '格式不正确', duration: 2000,icon:'none'}); 
        return false; 
      }
      else {
        wx.showToast({
            title: '校验通过'
        })
          let name =`nickName=${this.data.names}`
          const res = await request({url:'/a/u/user',method:'POST',data:name,header: {
            "Content-Type": "application/x-www-form-urlencoded"
          }})
          
          if(res.data.code==0){
            setTimeout(() => {
              wx.navigateTo({
                url: '../studyEdit/studyEdit?nickName='+this.data.names,
              })
             }, 2000);
          }else {
            wx.showToast({ title: '请求失败',icon:'none'}); 
          }
       
      }
  },
  formInputChange(e) {
    this.setData({
        names: e.detail.value
    })
  },
  onLoad: function (options) {
    this.setData({
      names:options.name,
    })
  },
})